<template>
    <div>
        <van-form>
       <van-field v-model='form.mobile' label='手机号' placeholder='手机号' :rules="[{'required':true,'message':'必须输入手机号'}]"/>
       <van-button @click='send'>发送</van-button>
        <van-field v-model='form.password' placeholder='密码'/>
        <van-field v-model='form.repassword' placeholder='确认密码'/>
        <van-field v-model='form.code' placeholder='验证码'/>
        <van-button @click='reg'>注册</van-button>
    </van-form>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                form:{}
            }
        },
        methods:{
            reg(){
                if(this.form.password != this.form.repassword){
                    alert('两次密码输入不一致')
                }
                this.$axios.post('users/userM',this.form).then(res=>{
                    if(res.data.code==200){
                        alert('注册成功')
                    }else{
                        alert(res.data.mes)
                    }
                })
            },
            send(){
                let reg=/^1[3-9]\d{9}$/
                if(!reg.test(this.form.mobile)){
                    alert('手机不合法')
                    return
                }
                this.$axios.get('users/smscode?mobile='+this.form.mobile).then(res=>{
                    alert('发送成功')
                    alert(res.data.scode)
                })
            }
        },
    }
</script>

<style scoped>

</style>